package com.jy.adscm.operation.base.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.annotation.AdscmLogger;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.base.bean.TaskWorkPlan;
import com.jy.adscm.operation.base.bean.TaskWorkPlanCc;
import com.jy.adscm.operation.base.service.TaskWorkPlanCcService;
import com.jy.adscm.operation.base.service.TaskWorkPlanService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 个人抄送人 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2020-05-29
 */
@RestController
@RequestMapping("/adscm/operation/taskWorkPlanCc")
public class TaskWorkPlanCcController {
    @Autowired
    TaskWorkPlanCcService taskWorkPlanCcService;

    @RequestMapping("insert/{tid}")
    public SimpleCoreResponse insert(@PathVariable Long tid, @RequestBody List<TaskWorkPlanCc> taskWorkPlanCcs, HttpServletRequest request) throws AdscmSystemException {
         //先清空这个tid所用的抄送人
        Wrapper<TaskWorkPlanCc> wrapper =new EntityWrapper<>();
        wrapper.eq("tid",tid);
        boolean delete = taskWorkPlanCcService.delete(wrapper);
        if (taskWorkPlanCcs!=null&&taskWorkPlanCcs.size()>0 ){
            for (TaskWorkPlanCc taskWorkPlanCc : taskWorkPlanCcs) {
                boolean insert = taskWorkPlanCcService.insert(taskWorkPlanCc);
            }
        }
        return new SimpleCoreResponse("200","新增成功",delete);
    }
    @RequestMapping("select/{tid}")
    public SimpleCoreResponse select(@PathVariable Long tid, HttpServletRequest request) throws AdscmSystemException {
         List<TaskWorkPlanCc>   taskWorkPlanCcs= taskWorkPlanCcService.select(tid);
        return new SimpleCoreResponse("200","查询成功",taskWorkPlanCcs);
    }


}

